package com.sojson.project.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sojson.config.exception.TransErrorCode;
import com.sojson.enums.core.EGeneralStatus;
import com.sojson.project.controller.param.verify.HotelRoomParamVerify;
import com.sojson.project.entity.po.HotelRoom;
import com.sojson.project.entity.vo.HotelRoomVo;
import com.sojson.project.query.entity.bo.Select;
import com.sojson.project.service.HotelRoomService;
import com.sojson.result.Result;
import com.sojson.util.StringUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 房间信息控制器
 * 
 * @author liu
 * @date 2021-07-02
 */
@Api(tags = "房间信息管理")
@RestController
@RequestMapping("/hotelRoom")
public class HotelRoomController {

    @Autowired
    private HotelRoomService hotelRoomService;

    /**
     * 单条插入
     * 
     * @param hotelRoom
     * @return
     */
    @PostMapping("/insert")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/insert')")
    @ApiOperation("给房间信息添加一条数据")
    public Result<Integer> insert(@RequestBody HotelRoom dto) {
        // 校验参数
        Result<Integer> paramResult = HotelRoomParamVerify.insert(dto);
        // 验证不通过
        if (!paramResult.getCode().equals(TransErrorCode.SUCCESS.getCode())) {
            return paramResult;
        }

        dto.insertInit();
        return Result.success(hotelRoomService.insert(dto));
    }

    /**
     * 批量插入
     * 
     * @param hotelRoom
     * @return
     */
    @PostMapping("/insertList")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/insertList')")
    @ApiOperation("给房间信息添加多条数据")
    public Result<Integer> insertList(@RequestBody HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.insertList(hotelRoom));
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param hotelRoom
     * @return
     */
    @DeleteMapping("/deleteByDto")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/deleteByDto')")
    @ApiOperation("通过对象批量删除房间信息数据(物理删除)")
    public Result<Integer> deleteByDto(@RequestBody HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.deleteByDto(hotelRoom));
    }

    /**
     * 统计全部数量
     * 
     * @return
     */
    @GetMapping("/countAll")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/countAll')")
    @ApiOperation("统计房间信息全部数据(包含逻辑删除的)")
    public Result<Integer> countAll() {
        return Result.success(hotelRoomService.countAll());
    }

    /**
     * 查询所有
     * 
     * @return
     */
    @GetMapping("/listAll")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/listAll')")
    @ApiOperation("查询房间信息所有数据(包含逻辑删除的)")
    public Result<List<HotelRoom>> listAll() {
        return Result.success(hotelRoomService.listAll());
    }

    /**
     * 根据对象统计数量
     * 
     * @param hotelRoom
     * @return
     */
    @GetMapping("/countByDto")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/countByDto')")
    @ApiOperation("根据对象统计房间信息数据")
    public Result<Integer> countByDto(HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.countByDto(hotelRoom));
    }

    /**
     * 根据对象查询
     * 
     * @param hotelRoom
     * @return
     */
    @GetMapping("/listByDto")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/listByDto')")
    @ApiOperation("根据对象查询房间信息数据")
    public Result<List<HotelRoom>> listByDto(HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.listByDto(hotelRoom));
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/deleteById/{id}')")
    @ApiOperation("通过id删除房间信息数据(物理删除)")
    public Result<Integer> deleteById(@PathVariable Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(hotelRoomService.deleteById(id));
    }

    /**
     * 通过id数组删除(物理删除)
     * 
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteByIds/{ids}")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/deleteByIds')")
    @ApiOperation("通过id数组删除房间信息数据(物理删除)")
    public Result<Integer> deleteByIds(@PathVariable Integer[] ids) {
        if (ids.length == 0) {
            return Result.success();
        }

        return Result.success(hotelRoomService.deleteByIds(ids));
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param hotelRoom
     * @return
     */
    @PutMapping("/updateAllById")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateAllById')")
    @ApiOperation("通过id更新房间信息数据(全部更新)")
    public Result<Integer> updateAllById(@RequestBody HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.updateAllById(hotelRoom));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param hotelRoom
     * @return
     */
    @PutMapping("/updateAllByIdList")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateAllByIdList')")
    @ApiOperation("通过id列表更新房间信息数据(全部更新)(更新内容相同)")
    public Result<Integer> updateAllByIdList(@RequestBody HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.updateAllByIdList(hotelRoom));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param hotelRoom
     * @return
     */
    @PutMapping("/updateDtoListAllById")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateDtoListAllById')")
    @ApiOperation("通过id列表更新房间信息数据(全部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListAllById(@RequestBody HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.updateDtoListAllById(hotelRoom));
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param dto
     * @return
     */
    @PutMapping("/updateById")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateById')")
    @ApiOperation("通过id更新房间信息数据(局部更新)")
    public Result<Integer> updateById(@RequestBody HotelRoom dto) {
        // 校验参数
        Result<Integer> paramResult = HotelRoomParamVerify.updateById(dto);
        // 验证不通过
        if (!paramResult.getCode().equals(TransErrorCode.SUCCESS.getCode())) {
            return paramResult;
        }

        dto.updateInit();
        return Result.success(hotelRoomService.updateById(dto));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param hotelRoom
     * @return
     */
    @PutMapping("/updateByIdList")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateByIdList')")
    @ApiOperation("通过id列表更新房间信息数据(局部更新)(更新内容相同)")
    public Result<Integer> updateByIdList(@RequestBody HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.updateByIdList(hotelRoom));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param hotelRoom
     * @return
     */
    @PutMapping("/updateDtoListById")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateDtoListById')")
    @ApiOperation("通过id列表更新房间信息数据(局部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListById(@RequestBody HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.updateDtoListById(hotelRoom));
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/findById/{id}')")
    @ApiOperation("通过id查询房间信息数据")
    public Result<HotelRoom> findById(@PathVariable String id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(hotelRoomService.findById(id));
    }

    /**
     * 通过id数组查询
     * 
     * @param ids
     * @return
     */
    @GetMapping("/findByIds/{ids}")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/findByIds/{ids}')")
    @ApiOperation("通过id数组查询房间信息数据")
    public Result<List<HotelRoom>> findByIds(@PathVariable Integer[] ids) {
        if (ids.length == 0) {
            return Result.success();
        }

        return Result.success(hotelRoomService.findByIds(ids));
    }

    /**
     * 通过对象查询id列表
     * 
     * @param hotelRoom
     * @return
     */
    @GetMapping("/findIdByDto")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/findIdByDto')")
    @ApiOperation("通过对象查询房间信息id列表")
    public Result<List<Integer>> findIdByDto(HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.findIdByDto(hotelRoom));
    }

    /**
     * 通过no删除(物理删除)
     * 
     * @param no
     * @return
     */
    @DeleteMapping("/deleteByNo/{no}")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/deleteByNo/{no}')")
    @ApiOperation("通过no删除房间信息数据(物理删除)")
    public Result<Integer> deleteByNo(@PathVariable String no) {
        if (no == null) {
            return Result.success();
        }

        return Result.success(hotelRoomService.deleteByNo(no));
    }

    /**
     * 通过no数组删除(物理删除)
     * 
     * @param nos
     * @return
     */
    @DeleteMapping("/deleteByNos/{nos}")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/deleteByNos/{nos}')")
    @ApiOperation("通过no数组删除房间信息数据(物理删除)")
    public Result<Integer> deleteByNos(@PathVariable String[] nos) {
        if (nos.length == 0) {
            return Result.success();
        }

        return Result.success(hotelRoomService.deleteByNos(nos));
    }

    /**
     * 通过no更新(全部更新)
     * 
     * @param hotelRoom
     * @return
     */
    @PutMapping("/updateAllByNo")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateAllByNo')")
    @ApiOperation("通过no更新房间信息数据(全部更新)")
    public Result<Integer> updateAllByNo(@RequestBody HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.updateAllByNo(hotelRoom));
    }

    /**
     * 通过no列表更新(全部更新)(更新内容相同)
     * 
     * @param hotelRoom
     * @return
     */
    @PutMapping("/updateAllByNoList")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateAllByNoList')")
    @ApiOperation("通过no列表更新房间信息数据(全部更新)(更新内容相同)")
    public Result<Integer> updateAllByNoList(@RequestBody HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.updateAllByNoList(hotelRoom));
    }

    /**
     * 通过no列表更新(全部更新)(更新内容不相同)
     * 
     * @param hotelRooms
     * @return
     */
    @PutMapping("/updateDtoListAllByNo")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateDtoListAllByNo')")
    @ApiOperation("通过no列表更新房间信息数据(全部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListAllByNo(@RequestBody HotelRoom hotelRooms) {
        return Result.success(hotelRoomService.updateDtoListAllByNo(hotelRooms));
    }

    /**
     * 通过no更新(局部更新)
     * 
     * @param hotelRoom
     * @return
     */
    @PutMapping("/updateByNo")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateByNo')")
    @ApiOperation("通过no更新房间信息数据(局部更新)")
    public Result<Integer> updateByNo(@RequestBody HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.updateByNo(hotelRoom));
    }

    /**
     * 通过no列表更新(局部更新)(更新内容相同)
     * 
     * @param hotelRoom
     * @return
     */
    @PutMapping("/updateByNoList")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateByNoList')")
    @ApiOperation("通过no列表更新房间信息数据(局部更新)(更新内容相同)")
    public Result<Integer> updateByNoList(@RequestBody HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.updateByNoList(hotelRoom));
    }

    /**
     * 通过no列表更新(局部更新)(更新内容不相同)
     * 
     * @param hotelRooms
     * @return
     */
    @PutMapping("/updateDtoListByNo")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/updateDtoListByNo')")
    @ApiOperation("通过no列表更新房间信息数据(局部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListByNo(@RequestBody HotelRoom hotelRooms) {
        return Result.success(hotelRoomService.updateDtoListByNo(hotelRooms));
    }

    /**
     * 通过no查询
     * 
     * @param no
     * @return
     */
    @GetMapping("/findByNo/{no}")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/findByNo/{no}')")
    @ApiOperation("通过no查询房间信息数据")
    public Result<HotelRoom> findByNo(@PathVariable String no) {
        if (no == null) {
            return Result.success();
        }

        return Result.success(hotelRoomService.findByNo(no));
    }

    /**
     * 通过no数组查询
     * 
     * @param nos
     * @return
     */
    @GetMapping("/findByNos/{nos}")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/findByNos/{nos}')")
    @ApiOperation("通过no数组查询房间信息数据")
    public Result<List<HotelRoom>> findByNos(@PathVariable String[] nos) {
        if (nos.length == 0) {
            return Result.success();
        }

        return Result.success(hotelRoomService.findByNos(nos));
    }

    /**
     * 通过对象查询no列表
     * 
     * @param hotelRoom
     * @return
     */
    @GetMapping("/findNoByDto")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/findNoByDto')")
    @ApiOperation("通过对象查询房间信息no列表")
    public Result<List<String>> findNoByDto(HotelRoom hotelRoom) {
        return Result.success(hotelRoomService.findNoByDto(hotelRoom));
    }

    /**
     * 清空数据(物理清空)
     * 
     * @return
     */
    @DeleteMapping("/clear")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/clear')")
    @ApiOperation("清空房间信息数据(物理清空)")
    public Result<Integer> clear() {
        return Result.success(hotelRoomService.clear());
    }

    /**
     * 根据对象查询
     * 
     * @param hotelRoom
     * @return
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('/hotelRoom/list')")
    @ApiOperation("根据对象查询房间信息数据")
    public Result<List<HotelRoomVo>> list(HotelRoomVo hotelRoom) {
        List<HotelRoomVo> list = hotelRoomService.list(hotelRoom);
        return Result.success(list);
    }

    /**
     * 根据对象查询
     * 
     * @param hotelRoom
     * @return
     */
    @GetMapping("/listApp")
    @ApiOperation("根据对象查询房间信息数据")
    public Result<List<HotelRoomVo>> listApp(HotelRoomVo hotelRoom) {
        hotelRoom.setStatus(EGeneralStatus.NORMAL.getCode());
        List<HotelRoomVo> list = hotelRoomService.list(hotelRoom);
        return Result.success(list);
    }

    /**
     * 通过no查询
     * 
     * @param no
     * @return
     */
    @GetMapping("/getInfo/{no}")
    @ApiOperation("通过no查询房间信息数据")
    public Result<HotelRoomVo> getInfo(@PathVariable String no) {
        if (no == null) {
            return Result.success();
        }

        return Result.success(hotelRoomService.getInfo(no));
    }

    /**
     * 获取下拉列表
     * 
     * @param hotelRoom
     * @return
     */
    @GetMapping("/select")
    @PreAuthorize("@ss.hasPermi('/select')")
    @ApiOperation("获取酒店房间下拉列表")
    public Result<List<Select>> select(HotelRoomVo hotelRoom) {
        List<Select> list = hotelRoomService.select(hotelRoom);
        return Result.success(list);
    }

    /**
     * 获取下拉列表
     * 
     * @param hotelRoom
     * @return
     */
    @GetMapping("/selectApp")
    @ApiOperation("获取酒店房间下拉列表")
    public Result<List<Select>> selectApp(HotelRoomVo hotelRoom) {
        hotelRoom.setStatus(EGeneralStatus.NORMAL.getCode());
        String name = hotelRoom.getName();
        if (StringUtil.isNotBlankObject(name) && name.indexOf(",") > 0) {
            hotelRoom.setNameHotel(name.substring(0, name.indexOf(",")));
            hotelRoom.setName(name.substring(name.indexOf(",") + 1));
        }
        List<Select> list = hotelRoomService.select(hotelRoom);
        return Result.success(list);
    }

}